
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>107简单题 · My Study Note</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="yanglonglong">
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-chapter-fold/chapter-fold.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-toggle-chapters/toggle.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-flexible-alerts/style.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-theme-comscore/test.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="2两数相加.html" />
    
    
    <link rel="prev" href="./" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
        
        <li>
            <a href="https://www.yangllong.top/" target="_blank" class="custom-link">My Blog</a>
        </li>
    
    

    
    <li class="divider"></li>
    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../../Linux相关/">
            
                <a href="../../Linux相关/">
            
                    
                    Linux相关
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../../Linux相关/make工具的使用.html">
            
                <a href="../../Linux相关/make工具的使用.html">
            
                    
                    Make工具的使用
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../../springboot/">
            
                <a href="../../springboot/">
            
                    
                    Springboot
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../../springboot/springboot一些遇到的问题.html">
            
                <a href="../../springboot/springboot一些遇到的问题.html">
            
                    
                    Springboot一些遇到的问题
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../../vue/">
            
                <a href="../../vue/">
            
                    
                    Vue
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../../vue/vue+ssm跨域问题.html">
            
                <a href="../../vue/vue+ssm跨域问题.html">
            
                    
                    Vue+Ssm跨域问题
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../../vue/vue-cli3.html">
            
                <a href="../../vue/vue-cli3.html">
            
                    
                    Vue Cli3
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../../vue/安装vue.html">
            
                <a href="../../vue/安装vue.html">
            
                    
                    安装Vue
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../../其他/">
            
                <a href="../../其他/">
            
                    
                    其他
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../../其他/分布式系统.html">
            
                <a href="../../其他/分布式系统.html">
            
                    
                    分布式系统
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../../其他/图解http.html">
            
                <a href="../../其他/图解http.html">
            
                    
                    图解Http
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../../其他/消息队列.html">
            
                <a href="../../其他/消息队列.html">
            
                    
                    消息队列
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../../其他/爬虫.html">
            
                <a href="../../其他/爬虫.html">
            
                    
                    爬虫
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../">
            
                <a href="../">
            
                    
                    刷题
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../NOJ.html">
            
                <a href="../NOJ.html">
            
                    
                    NOJ
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="./">
            
                <a href="./">
            
                    
                    Leetcode
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.6.3" data-path="107简单题.html">
            
                <a href="107简单题.html">
            
                    
                    107简单题
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.3.1" data-path="2两数相加.html">
            
                <a href="2两数相加.html">
            
                    
                    2两数相加
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3.2" data-path="3无重复子串的最大长度.html">
            
                <a href="3无重复子串的最大长度.html">
            
                    
                    3无重复子串的最大长度
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="../扇贝杯csdn.html">
            
                <a href="../扇贝杯csdn.html">
            
                    
                    扇贝杯Csdn
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="../排序算法.html">
            
                <a href="../排序算法.html">
            
                    
                    排序算法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" data-path="../蓝桥杯.html">
            
                <a href="../蓝桥杯.html">
            
                    
                    蓝桥杯
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.7" data-path="../蓝桥杯热身赛.html">
            
                <a href="../蓝桥杯热身赛.html">
            
                    
                    蓝桥杯热身赛
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.8" data-path="../计算机等级考试(C语言">
            
                <span>
            
                    
                    计算机等级考试(C语言)
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../../博客/">
            
                <a href="../../博客/">
            
                    
                    博客
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../../博客/next主题配置.html">
            
                <a href="../../博客/next主题配置.html">
            
                    
                    Next主题配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../../博客/一些问题的记录.html">
            
                <a href="../../博客/一些问题的记录.html">
            
                    
                    一些问题的记录
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../../学习java/">
            
                <a href="../../学习java/">
            
                    
                    学习Java
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../../学习java/AQS.html">
            
                <a href="../../学习java/AQS.html">
            
                    
                    AQS
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="../../学习java/HashMap的简单实现.html">
            
                <a href="../../学习java/HashMap的简单实现.html">
            
                    
                    HashMap的简单实现
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="../../学习java/JavaByteCode.html">
            
                <a href="../../学习java/JavaByteCode.html">
            
                    
                    JavaByteCode
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.4" data-path="../../学习java/Java基础.html">
            
                <a href="../../学习java/Java基础.html">
            
                    
                    Java基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.5" data-path="../../学习java/Java多线程.html">
            
                <a href="../../学习java/Java多线程.html">
            
                    
                    Java多线程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.6" data-path="../../学习java/Java多线程并发.html">
            
                <a href="../../学习java/Java多线程并发.html">
            
                    
                    Java多线程并发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.7" data-path="../../学习java/Java爬虫.html">
            
                <a href="../../学习java/Java爬虫.html">
            
                    
                    Java爬虫
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.8" data-path="../../学习java/Java集合.html">
            
                <a href="../../学习java/Java集合.html">
            
                    
                    Java集合
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.9" data-path="../../学习java/java常用类.html">
            
                <a href="../../学习java/java常用类.html">
            
                    
                    Java常用类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.10" data-path="../../学习java/jvm.html">
            
                <a href="../../学习java/jvm.html">
            
                    
                    Jvm
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.11" data-path="../../学习java/noifelse.html">
            
                <a href="../../学习java/noifelse.html">
            
                    
                    Noifelse
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.12" data-path="../../学习java/socket.html">
            
                <a href="../../学习java/socket.html">
            
                    
                    Socket
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.13" data-path="../../学习java/一些Java方法.html">
            
                <a href="../../学习java/一些Java方法.html">
            
                    
                    一些Java方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.14" data-path="../../学习java/一些其他人写的博客.html">
            
                <a href="../../学习java/一些其他人写的博客.html">
            
                    
                    一些其他人写的博客
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.15" data-path="../../学习java/硬核空间.html">
            
                <a href="../../学习java/硬核空间.html">
            
                    
                    硬核空间
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.16" data-path="../../学习java/遇到的问题.html">
            
                <a href="../../学习java/遇到的问题.html">
            
                    
                    遇到的问题
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.17" data-path="../../学习java/阻塞队列.html">
            
                <a href="../../学习java/阻塞队列.html">
            
                    
                    阻塞队列
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../../安卓开发/">
            
                <a href="../../安卓开发/">
            
                    
                    安卓开发
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="../../安卓开发/First App.html">
            
                <a href="../../安卓开发/First App.html">
            
                    
                    First App
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.2" data-path="../../安卓开发/problems.html">
            
                <a href="../../安卓开发/problems.html">
            
                    
                    Problems
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../../工具/">
            
                <a href="../../工具/">
            
                    
                    工具
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.10.1" data-path="../../工具/IDEA.html">
            
                <a href="../../工具/IDEA.html">
            
                    
                    IDEA
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.2" data-path="../../工具/docker.html">
            
                <a href="../../工具/docker.html">
            
                    
                    Docker
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.3" data-path="../../工具/github.html">
            
                <a href="../../工具/github.html">
            
                    
                    Github
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../../数据库/">
            
                <a href="../../数据库/">
            
                    
                    数据库
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.11.1" data-path="../../数据库/MVCC.html">
            
                <a href="../../数据库/MVCC.html">
            
                    
                    MVCC
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2" data-path="../../数据库/MySQL.html">
            
                <a href="../../数据库/MySQL.html">
            
                    
                    MySQL
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.3" data-path="../../数据库/Redis.html">
            
                <a href="../../数据库/Redis.html">
            
                    
                    Redis
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="../../数据结构知识/">
            
                <a href="../../数据结构知识/">
            
                    
                    数据结构知识
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.12.1" data-path="../../数据结构知识/大话数据结构笔记1.html">
            
                <a href="../../数据结构知识/大话数据结构笔记1.html">
            
                    
                    大话数据结构笔记1
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.2" data-path="../../数据结构知识/大话数据结构笔记2.html">
            
                <a href="../../数据结构知识/大话数据结构笔记2.html">
            
                    
                    大话数据结构笔记2
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="../../面试笔试/">
            
                <a href="../../面试笔试/">
            
                    
                    面试笔试
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.13.1" data-path="../../面试笔试/字节跳动5月11日笔试.html">
            
                <a href="../../面试笔试/字节跳动5月11日笔试.html">
            
                    
                    字节跳动5月11日笔试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.2" data-path="../../面试笔试/阿里3月23日笔试.html">
            
                <a href="../../面试笔试/阿里3月23日笔试.html">
            
                    
                    阿里3月23日笔试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.3" data-path="../../面试笔试/面试突击.html">
            
                <a href="../../面试笔试/面试突击.html">
            
                    
                    面试突击
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >107简单题</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h4 id="107&#x7B80;&#x5355;&#x9898;">10.7&#x7B80;&#x5355;&#x9898;</h4>
<h5 id="1ip&#x5730;&#x5740;&#x65E0;&#x6548;&#x5316;">1.IP&#x5730;&#x5740;&#x65E0;&#x6548;&#x5316;</h5>
<blockquote>
<p>&#x6240;&#x8C13;&#x65E0;&#x6548;&#x5316; IP &#x5730;&#x5740;&#xFF0C;&#x5176;&#x5B9E;&#x5C31;&#x662F;&#x7528; <code>&quot;[.]&quot;</code> &#x4EE3;&#x66FF;&#x4E86;&#x6BCF;&#x4E2A; <code>&quot;.&quot;</code>&#x3002;</p>
</blockquote>
<p><strong>&#x793A;&#x4F8B; 1&#xFF1A;</strong></p>
<blockquote>
<p>&#x8F93;&#x5165;&#xFF1A;address = &quot;1.1.1.1&quot;
&#x8F93;&#x51FA;&#xFF1A;&quot;1[.]1[.]1[.]1&quot;</p>
</blockquote>
<p>&#x76F4;&#x63A5;&#x4F7F;&#x7528;&#x4E86;replace&#x51FD;&#x6570;</p>
<pre><code class="lang-java"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Solution</span> </span>{
    <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">defangIPaddr</span><span class="hljs-params">(String address)</span> </span>{
        <span class="hljs-keyword">return</span> address.replace(<span class="hljs-string">&quot;.&quot;</span>,<span class="hljs-string">&quot;[.]&quot;</span>);
    }
}
</code></pre>
<h5 id="2&#x731C;&#x6570;&#x5B57;">2.&#x731C;&#x6570;&#x5B57;</h5>
<p>&#x5E94;&#x8BE5;&#x662F;&#x6700;&#x7B80;&#x5355;&#x7684;&#x9898;&#x4E86;&#x5427;</p>
<pre><code class="lang-java"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Solution</span> </span>{
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">int</span> <span class="hljs-title">game</span><span class="hljs-params">(<span class="hljs-keyword">int</span>[] guess, <span class="hljs-keyword">int</span>[] answer)</span> </span>{
        <span class="hljs-keyword">int</span> count = <span class="hljs-number">0</span>;
        <span class="hljs-keyword">for</span>(<span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>; i&lt;<span class="hljs-number">3</span>; i++){
            <span class="hljs-keyword">if</span>(guess[i]==answer[i])count++;
        }
        <span class="hljs-keyword">return</span> count;
    }
}
</code></pre>
<h5 id="3&#x5220;&#x9664;&#x94FE;&#x8868;&#x4E2D;&#x7684;&#x8282;&#x70B9;">3.&#x5220;&#x9664;&#x94FE;&#x8868;&#x4E2D;&#x7684;&#x8282;&#x70B9;</h5>
<p><strong>&#x793A;&#x4F8B;</strong></p>
<blockquote>
<p>&#x8F93;&#x5165;: head = [4,5,1,9], node = 5
&#x8F93;&#x51FA;: [4,1,9]
&#x89E3;&#x91CA;: &#x7ED9;&#x5B9A;&#x4F60;&#x94FE;&#x8868;&#x4E2D;&#x503C;&#x4E3A; 5 &#x7684;&#x7B2C;&#x4E8C;&#x4E2A;&#x8282;&#x70B9;&#xFF0C;&#x90A3;&#x4E48;&#x5728;&#x8C03;&#x7528;&#x4E86;&#x4F60;&#x7684;&#x51FD;&#x6570;&#x4E4B;&#x540E;&#xFF0C;&#x8BE5;&#x94FE;&#x8868;&#x5E94;&#x53D8;&#x4E3A; 4 -&gt; 1 -&gt; 9.</p>
</blockquote>
<pre><code class="lang-java"><span class="hljs-comment">/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode(int x) { val = x; }
 * }
 */</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Solution</span> </span>{
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">deleteNode</span><span class="hljs-params">(ListNode node)</span> </span>{
      node.val=node.next.val;
      node.next=node.next.next;
    }
}
</code></pre>
<p><strong>&#x662F;&#x6211;&#x60F3;&#x591A;&#x4E86;&#xFF0C;&#x4E0D;&#x9700;&#x8981;&#x7528;&#x5230;&#x524D;&#x4E00;&#x4E2A;&#x8282;&#x70B9;&#x3002;&#x76F4;&#x63A5;&#x628A;&#x5F53;&#x524D;&#x8282;&#x70B9;&#x7684;&#x503C;&#x548C;&#x201C;&#x6307;&#x9488;&#x201D;&#x90FD;&#x6539;&#x4E3A;&#x4E0B;&#x4E00;&#x4E2A;&#x5C31;&#x597D;&#x4E86;</strong></p>
<h5 id="4&#x4E8C;&#x53C9;&#x641C;&#x7D22;&#x6811;&#x7684;&#x8303;&#x56F4;&#x548C;">4.&#x4E8C;&#x53C9;&#x641C;&#x7D22;&#x6811;&#x7684;&#x8303;&#x56F4;&#x548C;</h5>
<blockquote>
<p>&#x7ED9;&#x5B9A;&#x4E8C;&#x53C9;&#x641C;&#x7D22;&#x6811;&#x7684;&#x6839;&#x7ED3;&#x70B9; <code>root</code>&#xFF0C;&#x8FD4;&#x56DE; <code>L</code> &#x548C; <code>R</code>&#xFF08;&#x542B;&#xFF09;&#x4E4B;&#x95F4;&#x7684;&#x6240;&#x6709;&#x7ED3;&#x70B9;&#x7684;&#x503C;&#x7684;&#x548C;&#x3002;</p>
<p>&#x4E8C;&#x53C9;&#x641C;&#x7D22;&#x6811;&#x4FDD;&#x8BC1;&#x5177;&#x6709;&#x552F;&#x4E00;&#x7684;&#x503C;&#x3002;</p>
</blockquote>
<p><strong>&#x793A;&#x4F8B;</strong></p>
<blockquote>
<p>&#x8F93;&#x5165;&#xFF1A;root = [10,5,15,3,7,null,18], L = 7, R = 15
&#x8F93;&#x51FA;&#xFF1A;32</p>
</blockquote>
<p><strong>&#x9012;&#x5F52;&#x5B9E;&#x73B0;&#x6DF1;&#x5EA6;&#x4F18;&#x5148;&#x641C;&#x7D22;</strong></p>
<pre><code class="lang-java"><span class="hljs-comment">/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Solution</span> </span>{
     <span class="hljs-keyword">int</span> result;
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">int</span> <span class="hljs-title">rangeSumBST</span><span class="hljs-params">(TreeNode root, <span class="hljs-keyword">int</span> L, <span class="hljs-keyword">int</span> R)</span> </span>{
        result=<span class="hljs-number">0</span>;
        dfs(root,L,R);
        <span class="hljs-keyword">return</span> result;
    }

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">dfs</span><span class="hljs-params">(TreeNode node, <span class="hljs-keyword">int</span> L, <span class="hljs-keyword">int</span> R)</span></span>{
        <span class="hljs-keyword">if</span>(node!=<span class="hljs-keyword">null</span>){
            <span class="hljs-keyword">if</span>(node.val&gt;=L&amp;&amp;node.val&lt;=R)
                result+=node.val;
            <span class="hljs-keyword">if</span>(node.val&lt;R)
                dfs(node.right,L, R);
            <span class="hljs-keyword">if</span>(node.val&gt;L)
                dfs(node.left,L, R);
        }
    }

}
</code></pre>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="./" class="navigation navigation-prev " aria-label="Previous page: Leetcode">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="2两数相加.html" class="navigation navigation-next " aria-label="Next page: 2两数相加">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"107简单题","level":"1.6.3","depth":2,"next":{"title":"2两数相加","level":"1.6.3.1","depth":3,"path":"刷题/leetcode/2两数相加.md","ref":"刷题/leetcode/2两数相加.md","articles":[]},"previous":{"title":"Leetcode","level":"1.6.2","depth":2,"path":"刷题/leetcode/README.md","ref":"刷题/leetcode/README.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-search","-lunr","-sharing","-anchor-navigation-ex","todo","code","-katex","github","-summary","search-pro","chapter-fold","theme-comscore","toggle-chapters","flexible-alerts"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"chapter-fold":{},"github":{"url":"https://github.com/BluePrintYang"},"todo":{},"search-pro":{},"code":{"copyButtons":true},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"anchor-navigation-ex":{"showLevel":false,"showGoTop":true,"isRewritePageTitle":true,"isShowTocTitleIcon":true,"tocLevel1Icon":"fa fa-hand-o-right","tocLevel2Icon":"fa fa-hand-o-right","tocLevel3Icon":"fa fa-hand-o-right"},"theme-comscore":{},"flexible-alerts":{"danger":{"className":"danger","icon":"fa fa-ban","label":"Attention"},"note":{"className":"info","icon":"fa fa-info-circle","label":"Note"},"style":"callout","tip":{"className":"tip","icon":"fa fa-lightbulb-o","label":"Tip"},"warning":{"className":"warning","icon":"fa fa-exclamation-triangle","label":"Warning"}},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"toggle-chapters":{}},"theme":"default","author":"yanglonglong","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"My Study Note","language":"zh-hans","links":{"sidebar":{"My Blog":"https://www.yangllong.top/"}},"gitbook":"*"},"file":{"path":"刷题/leetcode/107简单题.md","mtime":"2020-06-29T16:04:36.000Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-01-14T07:15:50.272Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-github/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-chapter-fold/chapter-fold.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-toggle-chapters/toggle.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-flexible-alerts/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-theme-comscore/test.js"></script>
        
    

    </body>
</html>

